package com.zrrd.learn.chapter06数组;

import java.util.Arrays;

/**
 * 数组练习
 *
 * @author wrn
 * @version 1.0
 * @date 2023/7/13 10:12
 */

public class ArrayLianxi02 {


    /**
     * 小明要去买一部手机，他询问了四家店的价格，分别是2800.5元，2900元，2750.0元和3100元 显示输出最低价
     *
     * @param price
     */
    public static void question1(double[] price) {

        Arrays.sort(price);
        System.out.println(Arrays.toString(price));
        System.out.printf("最低价" + price[0]);
        System.out.printf("\n");

    }

    /**
     * 任意一个人输入年龄，就可以判断出他是哪个年龄段的人？
     * 0-9 垂髫之年；10-19 志学之年；20-29 弱冠之年；
     * 30-39 而立之年；40-49 不惑之年；50-59 知命之年；
     * 60-69 花甲之年；70-79 古稀之年；80-89 杖朝之年；
     * 90-99 耄耋之年
     *
     * @param age
     */
    public static void question2(int age) {

        int ageid = age / 10;
        String[] agegroup = {"垂髫之年", "志学之年", "弱冠之年", "而立之年", "不惑之年", "知命之年", "花甲之年", "古稀之年", "杖朝之年", "耄耋之年"};
        System.out.printf("您的年龄是" + age + "\n您已经是" + agegroup[ageid]);
        System.out.printf("\n");

    }

    /**
     * 把一个数组的元素逆序交换,
     * int[] a = { 5, 11, 15, 24, 36, 47, 59, 66 };
     * 交换元素后int[] b = { 66 ,59 ,47 ,36 ,24,15 ,11 ,5 };
     * @param a
     */

    public static void question3(int[] a) {
        int arrlo = a.length;
        int[] b = new int[arrlo];
        for (int i = 0; i < b.length; i++) {
            b[i] = a[a.length-1-i];
        }
        System.out.printf("交换前" + Arrays.toString(a));
        System.out.printf("\n交换后" + Arrays.toString(b));
        System.out.printf("\n");

    }

    /**
     * 随机产生10个元素（10——99范围），保存到数组中，查找里面是否有>80，
     * 如果有，显示有，否则提示没有
     * @param arrlength
     * @return
     */
    public static void question4(int arrlength) {
        int[] random = new int[arrlength];
        int num = 0;
        for (int i = 0; i < random.length; i++) {
            random[i] = (int)(Math.random()*90+10);
        }
        System.out.printf("生成的随机数数组是:" + Arrays.toString(random));
        for (int i = 0; i < random.length; i++) {
            if (random[i] > 80){
                num++;
            }
        }
        if (num > 0){
            System.out.printf("\n有");
        } else {
            System.out.printf("\n没有");
        }
    }






    public static void main(String[] args) {

        System.out.printf("1题\n");
        double[] price = {2800.5, 2900, 2750.0, 3100};
        question1(price);

//        System.out.printf("2题\n");
//        Scanner scanner = new Scanner(System.in);
//        System.out.print("请输入你的年龄");
//        int age = scanner.nextInt();
//        question2(age);

        System.out.printf("3题\n");
        int[] a = { 5, 11, 15, 24, 36, 47, 59, 66 };
        question3(a);

//        System.out.printf("4题\n");
//        Scanner scanner = new Scanner(System.in);
//        System.out.print("请输入数组长度");
//        int arrlength = scanner.nextInt();
//        question4(arrlength);




    }
}
